// var $parentNode = window.parent.document;

// function $childNode(name) {
//     return window.frames[name]
// }

// // tooltips
// $('.tooltip-demo').tooltip({
//     selector: "[data-toggle=tooltip]",
//     container: "body"
// });

// // 使用animation.css修改Bootstrap Modal
// $('.modal').appendTo("body");

// $("[data-toggle=popover]").popover();


//判断当前页面是否在iframe中
if (top == this) {
    var gohome = '<div class="gohome"><a class="animated bounceInUp" href="/Admin/Index/index.html?v=4.0" title="返回首页"><i class="fa fa-home"></i></a></div>';
    $('body').append(gohome);
}

//animation.css
function animationHover(element, animation) {
    element = $(element);
    element.hover(
        function () {
            element.addClass('animated ' + animation);
        },
        function () {
            //动画完成之前移除class
            window.setTimeout(function () {
                element.removeClass('animated ' + animation);
            }, 2000);
        });
}

//拖动面板
function WinMove() {
    var element = "[class*=col]";
    var handle = ".ibox-title";
    var connect = "[class*=col]";
    $(element).sortable({
            handle: handle,
            connectWith: connect,
            tolerance: 'pointer',
            forcePlaceholderSize: true,
            opacity: 0.8,
        })
        .disableSelection();
};

// 自定义正则类  依赖 jquery layer 
var strCheck = {
    mobileReg   :/0?(13|14|15|16|18|17|19)[0-9]{9}/,
    emailReg    :/\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/,
    chineseReg  :/[\u4e00-\u9fa5]/,
    emptyReg    :/\S/,
    
    mobile   :function(str){
        return this.mobileReg.test(str);
    },
    email    :function(str){
        return this.emailReg.test(str);
    },
    chinese  :function(str){
        return this.chineseReg.test(str);
    },
    check    :function(set){  //用法与 checkForm 一样
        var elem = $(set.elem), value = elem.val(), 
            type = elem.attr('check-type'),
            success = set.success||this.success, 
            error = set.error||this.error,
            event = set.event;
        if(value.length<=0 || !type) return;

        var re = this[type](value);
            if(re){
                success(elem);
            }else{
                error(elem);
            }
        
    },
     /**
      set 是一个对象 如: 
        {
          elem:'form',
          success:function(){},
          error:function(){}
        }
        其中 success、error 不传入 将使用默认方法
      *  */
    checkForm  :function(set){
        var isSubmint = true, //返回值 true表单可以提交 false 表单项有错误,不能提交
        success = set.success||this.success,
        error   = set.error||this.error;

        $(set.elem+" .str-check").each(function(){
            var elem = $(this), value = elem.val(),
                type = elem.attr('check-type');
            if(value.length>0) {
                var re = strCheck[type](value);
                if(re){
                    success(elem);
                }else{
                    error(elem);
                    isSubmint = false;
                }
            }else{
                isSubmint='empty';
            }
        });

        return isSubmint;

    },
    checkEmpty  :function(set){
        var isSubmint = true; //返回值 true表单可以提交 false 表单项有错误,不能提交

        $(set.elem+" .str-check").each(function(){

            var elem = $(this), value = elem.val();
            if(value.length>0) {
                elem.css({'border-radius':'2px','box-shadow':'inset rgb(255, 87, 34) 0px 0px 0px 0px'});
            }else{
                isSubmint = false;
                elem.css({'border-radius':'2px','box-shadow':'inset rgb(255, 87, 34) 0px 0px 2px 1px'});
                layer.tips('请填写内容！', elem , {
                    tips: [2, '#FF3030'],
                    time: 2000,
                    tipsMore: true
                });
            }

        });

        return isSubmint;
    },
    

    //默认提示样式如果需要修改请自己传入 success 和 error 这两个函数
    success  : function(e){
        e.css({'border-radius':'2px','box-shadow':'inset rgb(255, 87, 34) 0px 0px 0px 0px'});
    },
    error   : function(e){
        
        e.css({'border-radius':'2px','box-shadow':'inset rgb(255, 87, 34) 0px 0px 2px 1px'});
        layer.tips('格式错误！', e , {
            tips: [2, '#FF3030'],
            time: 2000,
            tipsMore: true
        });
    }
    
}
